package com.jetgege.loginmvp.view;

import android.support.v7.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.jetgege.loginmvp.R;
import com.jetgege.loginmvp.other.User;
import com.jetgege.loginmvp.presenter.ILoginPresenter;
import com.jetgege.loginmvp.presenter.LoginPresenterImpl;

/**
 * A login screen that offers login via email/password.
 */
public class LoginActivity extends AppCompatActivity implements ILoginView,OnClickListener{

    private EditText et_Password,et_UserName;
    private View mProgressView;
    private Button bt_Login;
    private ProgressBar pb_progress;
    private ILoginPresenter loginPresenter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        et_UserName= (EditText) findViewById(R.id.et_UserName);
        et_Password = (EditText) findViewById(R.id.et_Password);

        bt_Login = (Button) findViewById(R.id.bt_Login);
        pb_progress= (ProgressBar) findViewById(R.id.pb_progress);

        loginPresenter = new LoginPresenterImpl(this);
        bt_Login.setOnClickListener(this);
    }

    @Override
    public void showProgress() {
        pb_progress.setVisibility(View.VISIBLE);
    }

    @Override
    public void hideProgress() {
        pb_progress.setVisibility(View.GONE);
    }

    @Override
    public void loginError(String error) {
        Toast.makeText(this,error,Toast.LENGTH_LONG).show();
    }

    @Override
    public void loginSuccess(User user) {
        Toast.makeText(this,"登录成功！",Toast.LENGTH_LONG).show();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.bt_Login:
                loginPresenter.validateCredentials(et_UserName.getText().toString().trim(),et_Password.getText().toString().trim());
                break;
        }
    }
}

